package com.sjhang.utils;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @description 当项目启动的时候，把这个类交给spring管理，然后调用init公开
 * @author -还怕大雨吗
 * @date 2021/8/17 16:10
 * @version 1.0
 */
@Component
public class ConstantYml implements InitializingBean {

    /**从配置文件读取*/
    @Value("${aliyun.oss.endpoint}")
    private String endpoint;

    @Value("${aliyun.oss.access-key-id}")
    private String keyId;

    @Value("${aliyun.oss.access-key-secret}")
    private String keySecret;

    @Value("${aliyun.oss.bucket-name}")
    private String bucketName;


    /** 定义公开的变量 */
    public static String ENDPOINT;

    public static String ACCESSKEYID;

    public static String ACCESSKEYSECRET;

    public static String BUCKETNAME;


    /** 加载完成之后会执行这个方法 */
    @Override
    public void afterPropertiesSet() throws Exception {
        ENDPOINT = endpoint;
        ACCESSKEYID = keyId;
        ACCESSKEYSECRET = keySecret;
        BUCKETNAME = bucketName;
    }

}
